package com.hzqy.persistence.dao.hqjc;

import java.util.Collection;
import java.util.Iterator;

import javax.annotation.Resource;

import org.apache.ibatis.cache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hzqy.commons.utils.SystemConfigUtils;
import com.hzqy.persistence.dao.commons.CommonsDao;
import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.PmsUserVo;

@Repository
public class ClearCacheDao extends PersistenceDao<PmsUserVo, Integer> {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private CommonsDao commonsDao;
	
	
	public String clearCache(){
		StringBuffer sb = new StringBuffer();
		Collection<Cache> cacheCollection = getSqlSession().getConfiguration().getCaches();
		Iterator<Cache> cacheIter = cacheCollection.iterator();
		while(cacheIter.hasNext()) {
			Cache cache = cacheIter.next();
			LOG.debug("清除了二级缓存："+cache.getId()+"数量:"+cache.getSize());
			sb.append("清除了二级缓存："+cache.getId()+"数量:"+cache.getSize()+"<br/>");
			cache.clear();
		}
		SystemConfigUtils.init(commonsDao);
		return sb.toString();
	}
}
